#
# @lc app=leetcode.cn id=718 lang=python3
#
# [718] 最长重复子数组
#

# @lc code=start
class Solution:
    def findLength(self, nums1: List[int], nums2: List[int]) -> int:
        n1,n2 = len(nums1)+1,len(nums2)+1
        # dp[i][j]表示[0,i-1]的nums1和[0,j-1]的num2,最长重复子数组
        dp = [[0]*n2 for _ in range(n1)]
        res=0 #
        # dp[i][j] = dp[i-1]d[j-1]+1
        # i,j循环的范围1~数组长度
        for i in range(1, n1):
            for j in range(1, n2):
                if nums1[i-1]==nums2[j-1]:
                    dp[i][j]=dp[i-1][j-1]+1
                if dp[i][j]>res:
                    res=dp[i][j]
                    
                print(f'dp[{i}][{j}]={dp[i][j]}', end=' ')
                print(num1[0: i], num2[0: j], end=' ')
            print()

        return res
# @lc code=end

